package com.tledu.equipment.controller;

import com.tledu.common.annotation.Log;
import com.tledu.common.core.controller.BaseController;
import com.tledu.common.core.domain.AjaxResult;
import com.tledu.common.core.page.TableDataInfo;
import com.tledu.common.enums.BusinessType;
import com.tledu.common.utils.poi.ExcelUtil;
import com.tledu.equipment.domain.EquipmentInfo;
import com.tledu.equipment.domain.dto.TestResultDTO;
import com.tledu.equipment.service.IEquipmentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 参试设备Controller
 * 
 * @author ruoyi
 * @date 2024-08-29
 */
@RestController
@RequestMapping("/equipment/equipmentinfo")
public class EquipmentInfoController extends BaseController
{
    @Autowired
    private IEquipmentInfoService equipmentInfoService;

    /**
     * 查询参试设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentinfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentInfo equipmentInfo)
    {
        startPage();
        List<EquipmentInfo> list = equipmentInfoService.selectEquipmentInfoList(equipmentInfo);
        return getDataTable(list);
    }

    /**
     * 导出参试设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentinfo:export')")
    @Log(title = "参试设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentInfo equipmentInfo)
    {
        List<EquipmentInfo> list = equipmentInfoService.selectEquipmentInfoList(equipmentInfo);
        ExcelUtil<EquipmentInfo> util = new ExcelUtil<EquipmentInfo>(EquipmentInfo.class);
        util.exportExcel(response, list, "参试设备数据");
    }

    /**
     * 获取参试设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentinfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentInfoService.selectEquipmentInfoById(id));
    }

    /**
     * 新增参试设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentinfo:add')")
    @Log(title = "参试设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentInfo equipmentInfo)
    {
        return toAjax(equipmentInfoService.insertEquipmentInfo(equipmentInfo));
    }

    /**
     * 修改参试设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:equipmentinfo:edit')")
    @Log(title = "参试设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentInfo equipmentInfo)
    {
        return toAjax(equipmentInfoService.updateEquipmentInfo(equipmentInfo));
    }

    /**
     * 删除参试设备
     */
//    @PreAuthorize("@ss.hasPermi('equipment:equipmentinfo:remove')")
//    @Log(title = "参试设备", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(equipmentInfoService.deleteEquipmentInfoByIds(ids));
//    }

    /**
     * 逻辑删除
     */
    @PutMapping("/{ids}")
    public AjaxResult logicRemove(@PathVariable Long[] ids){
        return  toAjax(equipmentInfoService.logicDeleteEeupmentInfoByIds(ids));
    }

//    申请试验按钮逻辑
    @PutMapping("/applyForTest/{id}")
    public AjaxResult applyForTest(@PathVariable Long id){
        return toAjax(equipmentInfoService.applyForTest(id));
    }

    //实验结果按钮逻辑
//    @PutMapping("/resultOfTest/{id}")
//    public AjaxResult resultOfTest(@PathVariable Long id){
//        return toAjax(equipmentInfoService.resultOfTest(id));
//    }

//    出库按钮逻辑
    @PutMapping("/outOfStore/{id}")
    public AjaxResult outOfStore(@PathVariable Long id){
        return toAjax(equipmentInfoService.outOfStore(id));
    }

    // 入库按钮逻辑
    @PutMapping("/putInStore/{id}")
    public AjaxResult putInStore(@PathVariable Long id) {
        return toAjax(equipmentInfoService.putInStore(id));
    }

    //试验结果按钮逻辑
    @PutMapping("/resultOfTest")
    public AjaxResult resultOfTest(@RequestBody TestResultDTO testResultVO){
        return toAjax(equipmentInfoService.resultOfTest(testResultVO));
    }

}

